extends ../layout
block content
    .text-center
        h2 Are you a returning camper?
          br
          .button-spacer
          | Sign in with one of these options:
        a.btn.btn-lg.btn-block.btn-social.btn-primary(href='/email-signin')
            i.fa.fa-envelope
            | Sign in with Email
        a.btn.btn-lg.btn-block.btn-social.btn-github(href='/auth/github')
            i.fa.fa-github
            | Sign in with GitHub
        br
        p
            a(href="/deprecated-signin") Click here if you previously signed in using a different method.

    script.
      $(document).ready(function() {
        var method = localStorage.getItem('lastSigninMethod'),
          btnSelector = 'a.btn.btn-lg.btn-block.btn-social';
        if (method) {
          try {
            var obj = JSON.parse(method);
          } catch(e) {
            console.error('Invalid sign in object stored', method);
            return;
          }
          $.each($(btnSelector), function(i, item) {
            if (
              $(item).text() === obj.method &&
              $(item).hasClass(obj.methodClass)
            ) {
              $(item).addClass('active');
              $(item).attr('title', 'This is your last signin method');
              return false;
            }
          });
        }

        $(btnSelector).click(function() {
          var obj = {};
          $(this).removeClass('active');
          obj.methodClass = $(this).attr('class').split(' ').pop();
          obj.method = $(this).text();
          if(obj.method === "Sign in with Email" || obj.method === "Sign in with GitHub") {
            localStorage.setItem('lastSigninMethod', JSON.stringify(obj));
          } else {
            localStorage.removeItem('lastSigninMethod');
          }
        });
      });
